package com.zeus.mongo.helper;

import com.google.common.collect.Lists;
import org.springframework.data.mongodb.core.query.Criteria;

import java.util.List;

/**
 * @author magic
 * @date 19-7-18 上午10:49
 * @version 1.0.0
 * Description MongoHelper
 * 
 */
public class MongoHelper {

    private static ThreadLocal<List<Criteria>> threadLocal = new ThreadLocal<>();

    public static void add(Criteria criteria){
        List<Criteria> criteriaList = threadLocal.get() == null ? Lists.newArrayList() : threadLocal.get();
        criteriaList.add(criteria);
        threadLocal.set(criteriaList);
    }

    public static List<Criteria> get(){
        List<Criteria> criteriaList = threadLocal.get() == null ? Lists.newArrayList() : threadLocal.get();
        threadLocal.set(null);
        return criteriaList;
    }
}
